home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / Blitting Class Library / Secure Macintosh Ports / SecureGWorld.cp < prev    next >
Encoding:
Text File  |  1995-11-18  |  1.9 KB  |  82 lines  |  [TEXT/CWIE]

  1. // SecureGWorld.cp, the SecureGWorld class, useful for generating GWorlds
  2. //    for those who do not use a framework to make GWorlds for them.
  3.  
  4. // copyright © 1995, Macneil Shonle. All rights reserved.
  5.  
  6. #ifndef __SECUREGWORLD__
  7. #include <SecureGWorld.h>
  8. #endif
  9.  
  10. #ifndef __GWORLDSETTER__
  11. #include <GWorldSetter.h>
  12. #endif
  13.  
  14. // constructs the GWorld from the parameters
  15. //    may throw: xalloc, invalidargument
  16. SecureGWorld::SecureGWorld(const Rect &bounds, BitDepth depth, CTabHandle ctab)
  17.     throw(xalloc, invalidargument)
  18. {
  19.     QDErr err = ::NewGWorld(&gworld, depth, &bounds, ctab, nil, 0);
  20.     
  21.     if (err == noErr) {
  22.         GWorldSetter setTo(gworld);
  23.         
  24.         ::LockPixels(::GetGWorldPixMap(gworld));
  25.         ::ClipRect(&gworld->portRect);
  26.         ::EraseRect(&gworld->portRect);
  27.     }
  28.     else if (err == paramErr)
  29.         throw invalidargument("NewGWorld paramErr", "SecureGWorld::SecureGWorld");
  30.     else if (err == cDepthErr)
  31.         throw invalidargument("NewGWorld cDepthErr", "SecureGWorld::SecureGWorld");
  32.     else
  33.         throw xalloc("NewGWorld failed", "SecureGWorld::SecureGWorld");
  34. }
  35.  
  36. // disposes the GWorld
  37. SecureGWorld::~SecureGWorld()
  38. {
  39.     ::DisposeGWorld(gworld);
  40. }
  41.  
  42. // returns the GWorld's port-rectangle
  43. Rect& SecureGWorld::portRect() const
  44. {
  45.     return gworld->portRect;
  46. }
  47.  
  48. // returns a pointer to the GWorld's bit-map
  49. BitMapPtr SecureGWorld::bitMap() const
  50. {
  51.     return &GrafPtr(gworld)->portBits;
  52. }
  53.  
  54. // returns the GWorld's width
  55. short SecureGWorld::width() const
  56. {
  57.     return gworld->portRect.right - gworld->portRect.left;
  58. }
  59.  
  60. // returns the GWorld's height
  61. short SecureGWorld::height() const
  62. {
  63.     return gworld->portRect.bottom - gworld->portRect.top;
  64. }
  65.  
  66. // returns the GWorld as a CGrafPtr
  67. CGrafPtr SecureGWorld::getMacPort() const
  68. {
  69.     return CGrafPtr(gworld);
  70. }
  71.  
  72. // returns the graphics device of the GWorld
  73. GDHandle SecureGWorld::getMacGD() const
  74. {
  75.     return nil;
  76. }
  77.  
  78. // "returns" the GWorldPtr
  79. SecureGWorld::operator GWorldPtr() const
  80. {
  81.     return gworld;
  82. }